<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商户名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入商户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:business:add']"
        >注册</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleUpdate"
          v-hasPermi="['system:batch:remove']"
        >审核</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="businessList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商户id" align="center" prop="id" />
      <el-table-column label="商户名称" align="center" prop="name" />
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <span v-if="scope.row.type==1">
            个人房东
          </span>
          <span v-if="scope.row.type==0">
            公司化公寓
          </span>
        </template>
      </el-table-column>
      <el-table-column label="身份正号码" align="center" prop="certNum"/>
      <el-table-column label="公司" align="center" prop="corporation" />
      <el-table-column label="是否审核" align="center" prop="status" >
        <template slot-scope="scope">
          <span v-if="scope.row.status==3">
            已审核
          </span>
          <span v-else>
            未审核
          </span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { listBusiness, getBusiness, delBusiness, addBusiness, updateBusiness } from "@/api/business/info";

export default {
  name: "BusinessList",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户表格数据
      businessList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        corporation: null,
        province: null,
        city: null,
        county: null,
        address: null,
        type: null,
        status: null,
        userId: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        url: null,
        zheng: null,
        headPicture: null,
        legalPersonName: null,
        certNum: null,
        certPicture: null,
        certPicture2: null,
        certPicture3: null,
        brandName: null,
        apartmentUrl: null,
        serviceHotline: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商户列表 */
    getList() {
      this.loading = true;
      listBusiness(this.queryParams).then(response => {
        this.businessList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        corporation: null,
        province: null,
        city: null,
        county: null,
        address: null,
        type: null,
        status: 0,
        userId: null,
        createTime: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        url: null,
        zheng: null,
        headPicture: null,
        legalPersonName: null,
        certNum: null,
        certPicture: null,
        certPicture2: null,
        certPicture3: null,
        brandName: null,
        apartmentUrl: null,
        serviceHotline: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    /** 新增按钮操作 */
    handleAdd() {
      /*this.reset();
      this.open = true;*/
      this.$router.push("add")
      this.title = "注册商户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认审核商户编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return updateBusiness(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("审核成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/business/export', {
        ...this.queryParams
      }, `system_business.xlsx`)
    }
  }
};
</script>
